#coding=utf-8
#Boa:Dialog:DlgStaffEditor

import wx
from product import CDataStaff

def create(parent):
    return DlgStaffEditor(parent)

[wxID_DLGSTAFFEDITOR, wxID_DLGSTAFFEDITORBTNCANCEL, 
 wxID_DLGSTAFFEDITORBTNSAVE, wxID_DLGSTAFFEDITORTADDR, 
 wxID_DLGSTAFFEDITORTCADDR, wxID_DLGSTAFFEDITORTCEMERGENCY, 
 wxID_DLGSTAFFEDITORTCMEMO, wxID_DLGSTAFFEDITORTCNAME, 
 wxID_DLGSTAFFEDITORTCPHONE, wxID_DLGSTAFFEDITORTCPOST, 
 wxID_DLGSTAFFEDITORTEMERGENCY, wxID_DLGSTAFFEDITORTMEMO, 
 wxID_DLGSTAFFEDITORTNAME, wxID_DLGSTAFFEDITORTPHONE, 
 wxID_DLGSTAFFEDITORTPOST, 
] = [wx.NewId() for _init_ctrls in range(15)]

class DlgStaffEditor(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGSTAFFEDITOR, name=u'DlgStaffEditor',
              parent=prnt, pos=wx.Point(409, 263), size=wx.Size(387, 399),
              style=wx.DEFAULT_DIALOG_STYLE, title=u'\u5458\u5de5\u7f16\u8f91')
        self.SetClientSize(wx.Size(379, 365))

        self.tName = wx.StaticText(id=wxID_DLGSTAFFEDITORTNAME,
              label=u'\u5458\u5de5\u59d3\u540d\uff1a', name=u'tName',
              parent=self, pos=wx.Point(40, 40), size=wx.Size(60, 14), style=0)

        self.tcName = wx.TextCtrl(id=wxID_DLGSTAFFEDITORTCNAME, name=u'tcName',
              parent=self, pos=wx.Point(120, 32), size=wx.Size(100, 22),
              style=0, value=u'')

        self.tPost = wx.StaticText(id=wxID_DLGSTAFFEDITORTPOST,
              label=u'\u62c5\u4efb\u804c\u52a1\uff1a', name=u'tPost',
              parent=self, pos=wx.Point(40, 80), size=wx.Size(60, 14), style=0)

        self.tcPost = wx.TextCtrl(id=wxID_DLGSTAFFEDITORTCPOST, name=u'tcPost',
              parent=self, pos=wx.Point(120, 72), size=wx.Size(100, 22),
              style=0, value=u'')

        self.tPhone = wx.StaticText(id=wxID_DLGSTAFFEDITORTPHONE,
              label=u'\u8054\u7cfb\u7535\u8bdd\uff1a', name=u'tPhone',
              parent=self, pos=wx.Point(40, 120), size=wx.Size(60, 14),
              style=0)

        self.tcPhone = wx.TextCtrl(id=wxID_DLGSTAFFEDITORTCPHONE,
              name=u'tcPhone', parent=self, pos=wx.Point(120, 112),
              size=wx.Size(192, 22), style=0, value=u'')

        self.tAddr = wx.StaticText(id=wxID_DLGSTAFFEDITORTADDR,
              label=u'\u8054\u7cfb\u5730\u5740\uff1a', name=u'tAddr',
              parent=self, pos=wx.Point(40, 160), size=wx.Size(60, 14),
              style=0)

        self.tcAddr = wx.TextCtrl(id=wxID_DLGSTAFFEDITORTCADDR, name=u'tcAddr',
              parent=self, pos=wx.Point(120, 152), size=wx.Size(192, 22),
              style=0, value=u'')

        self.tEmergency = wx.StaticText(id=wxID_DLGSTAFFEDITORTEMERGENCY,
              label=u'\u7d27\u6025\u8054\u7cfb\u4eba\uff1a', name=u'tEmergency',
              parent=self, pos=wx.Point(40, 200), size=wx.Size(72, 14),
              style=0)

        self.tcEmergency = wx.TextCtrl(id=wxID_DLGSTAFFEDITORTCEMERGENCY,
              name=u'tcEmergency', parent=self, pos=wx.Point(120, 192),
              size=wx.Size(192, 22), style=0, value=u'')

        self.tMemo = wx.StaticText(id=wxID_DLGSTAFFEDITORTMEMO,
              label=u'\u5907\u6ce8\uff1a', name=u'tMemo', parent=self,
              pos=wx.Point(40, 240), size=wx.Size(36, 14), style=0)

        self.tcMemo = wx.TextCtrl(id=wxID_DLGSTAFFEDITORTCMEMO, name=u'tcMemo',
              parent=self, pos=wx.Point(120, 232), size=wx.Size(192, 22),
              style=0, value=u'')

        self.btnSave = wx.Button(id=wxID_DLGSTAFFEDITORBTNSAVE,
              label=u'\u4fdd\u5b58', name=u'btnSave', parent=self,
              pos=wx.Point(80, 296), size=wx.Size(75, 24), style=0)
        self.btnSave.Bind(wx.EVT_BUTTON, self.OnBtnSaveButton,
              id=wxID_DLGSTAFFEDITORBTNSAVE)

        self.btnCancel = wx.Button(id=wxID_DLGSTAFFEDITORBTNCANCEL,
              label=u'\u53d6\u6d88', name=u'btnCancel', parent=self,
              pos=wx.Point(192, 296), size=wx.Size(75, 24), style=0)
        self.btnCancel.Bind(wx.EVT_BUTTON, self.OnBtnCancelButton,
              id=wxID_DLGSTAFFEDITORBTNCANCEL)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        self.myInit()
        
        
    def myInit(self):
        self.staffObj = None

    def setStaff(self, staff):
        self.staffObj = staff

        self.tcName.SetValue(staff.getFieldVal(index=CDataStaff.COL_NAME))
        
        self.tcPost.SetValue(staff.getFieldVal(index=CDataStaff.COL_POST))
        
        self.tcPhone.SetValue(staff.getFieldVal(index=CDataStaff.COL_PHONE))
        
        self.tcAddr.SetValue(staff.getFieldVal(index=CDataStaff.COL_ADDR))
        
        self.tcEmergency.SetValue(staff.getFieldVal(index=CDataStaff.COL_MEMO))
        
        self.tcMemo.SetValue(staff.getFieldVal(index=CDataStaff.COL_EMERGENCY))    
        
    def OnBtnSaveButton(self, event):
        if (self.tcName.GetValue() == ''):
            dlg = wx.MessageDialog(self, u'必须设置员工姓名', u'提示',
                                    wx.OK|wx.ICON_ERROR)
            dlg.ShowModal()
            return
        
        data = {CDataStaff.COL_NAME:self.tcName.GetValue(),
                CDataStaff.COL_POST:self.tcPost.GetValue(),
                CDataStaff.COL_PHONE:self.tcPhone.GetValue(),
                CDataStaff.COL_ADDR:self.tcAddr.GetValue(),
                CDataStaff.COL_MEMO:self.tcEmergency.GetValue(),
                CDataStaff.COL_EMERGENCY:self.tcMemo.GetValue()}
        
        if (self.staffObj is not None):
            self.staffObj.setMulFieldVal(data)
            self.staffObj.update()
        else:
            obj = CDataStaff.factory()
            #data[CDataStaff.COL_ID] = CDataStaff.newAutoIncrId()
            # 140711
            #obj.assignNewId()
            obj.setMulFieldVal(data)
            obj.insert()

        self.Close()
        
        
    def OnBtnCancelButton(self, event):
        self.Close()
